'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-10-27 21:51:34
'''
#
# @lc app=leetcode.cn id=309 lang=python3
#
# [309] 最佳买卖股票时机含冷冻期
#

# @lc code=start
class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        if not prices:
            return 0
        cash = 0
        from sys import maxsize
        hold = -prices[0]
        free = 0
        for i in range(1, len(prices)):
            v=prices[i]
            new1 = max(cash, free)
            new2 = max(cash-v, hold)
            new3 = hold+v
            cash, hold, free = new1, new2, new3
        return max(cash, free)
# @lc code=end

